import java.util.Scanner;

public class Test {


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        //1.输入数据
        int T = scan.nextInt();//操作的位数
        scan.nextLine();
        String[] str = new String[T];
        for (int i = 0; i < T; i++) {
            String S = scan.nextLine();
            str[i] = S;
        }
        //记录操作次数
        for (int i = 0; i < T; i++) {
            int s = str[i].length();
            System.out.println(s-T);
        }
        scan.close();
    }
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        StringBuilder str = new StringBuilder();
        long n = scan.nextInt();
        while(n > 0) {
            n--;
            char ch = (char) (n%26+'A');//1 <= n%26 < 26
            str.append(ch);
            n = n/26;
        }
        System.out.println(str.reverse());
        scan.close();
    }
}
